﻿(function(S){
 var dom = S.DOM;
 var lis = S.query("#item2 li"),spans = S.query("#item2 span");
 for(var i=0;i<lis.length;i++){
 (function(){
  var j = i;
  lis[j].onmouseover = function(){
  for(var k=0;k<lis.length;k++){
  var m = k;
  if(m !== j){
  spans[m].style.display = "none";
  }else{
  spans[m].style.display = "block";
  }
  }
  }
  lis[j].onmouseout = function(){
  spans[j].style.display = "none";
  }
  })()
 }
 var inputs = S.query("#zp_wrap input"),as = S.query("#zp_wrap .ms"),fqs = S.query("#zp_wrap .fq"),msgs = S.query("#zp_msg div");
 var tag_arr = new Array("false","false","false","false","true");
 var fqs_arr = new Array("false","false","false","false","true");
 for(var i=0;i<msgs.length;i++){
	 msgs[i].style.display = "none";
 }
 function msg(num){
	 var h = document.body.offsetHeight;
	 dom.get("#zp_mask2").style.height = h + "px";
	 dom.get("#zp_mask2").style.display = "block";
	 msgs[num].style.display = "block";
	 var div = msgs[num].getElementsByTagName("area");
	 for(var i=0; i<div.length; i++){
		 (function(i){
		  div[i].onclick = function(){
		  msgs[num].style.display = "none";
		  dom.get("#zp_mask2").style.display = "none";
		  if((num == 0)&&(i == 0)){
		  dom.get("#hide_ty").style.display = "none";
		  dom.get("#zp_mask").style.display = "none";
		  }
		  return false;
		  }
		  })(i)
	 }
 }
 /*获取时间*/
 function getServerDate(func) {
	 S.IO({
type:'HEAD',
cache:false,
url:window.location.href,
success:function(data, status, xhr) {
var date = new Date(xhr.getResponseHeader('Date'));
// console.log(date)
var time = (date.getMonth()+1) + '月' + date.getDate() + '日' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
func(date);
}
});
}
function showTime(time) {
	var m = parseInt(time.getMonth()+1,10),
		d = parseInt(time.getDate(),10),
		h = parseInt(time.getHours(),10);
	//if((m == 12)&&(d>=7)&&(d<=13)||true){
		for (var i = 0; i < 4; i++) {
			as[i].className = "ms";
			tag_arr[i] = "true";
			fqs[i].className = "fq";
			fqs_arr[i] = "true";
		}
		/*if(h>=10&&h<14||true){
			as[0].className = "ms";
			tag_arr[0] = "true";
			as[3].className = "ms close";
			tag_arr[3] = "false";
			fqs[0].className = "fq";
			fqs_arr[0] = "true";
			fqs[3].className = "fq finish";
			fqs_arr[3] = "false";
		}else if(h>=14&&h<15||true){
			as[0].className = "ms close";
			tag_arr[0] = "false";
			as[1].className = "ms";
			tag_arr[1] = "true";
			fqs[0].className = "fq finish";
			fqs_arr[0] = "false";
			fqs[1].className = "fq";
			fqs_arr[1] = "true";
		}else if(h>=15&&h<20||true){
			as[0].className = "ms close";
			tag_arr[0] = "false";
			as[1].className = "ms close";
			tag_arr[1] = "false";
			as[2].className = "ms";
			tag_arr[2] = "true";
			fqs[0].className = "fq finish";
			fqs_arr[0] = "false";
			fqs[1].className = "fq finish";
			fqs_arr[1] = "false";
			fqs[2].className = "fq";
			fqs_arr[2] = "true";
		/*}else if(h>=20&&h<24||true){
			as[0].className = "ms close";
			tag_arr[0] = "false";
			as[1].className = "ms close";
			tag_arr[1] = "false";
			as[2].className = "ms close";
			tag_arr[2] = "false";
			as[3].className = "ms";
			tag_arr[3] = "true";
			fqs[0].className = "fq finish";
			fqs_arr[0] = "false";
			fqs[1].className = "fq finish";
			fqs_arr[1] = "false";
			fqs[2].className = "fq finish";
			fqs_arr[2] = "false";
			fqs[3].className = "fq";
			fqs_arr[3] = "true";
		}else{
			as[0].className = "ms close";
			tag_arr[0] = "false";
			as[1].className = "ms close";
			tag_arr[1] = "false";
			as[2].className = "ms close";
			tag_arr[2] = "false";
			as[3].className = "ms close";
			tag_arr[3] = "false";
			fqs[0].className = "fq finish";
			fqs_arr[0] = "false";
			fqs[1].className = "fq finish";
			fqs_arr[1] = "false";
			fqs[2].className = "fq finish";
			fqs_arr[2] = "false";
			fqs[3].className = "fq finish";
			fqs_arr[3] = "false";
		}*/
	//}
}
getServerDate(showTime);
for(var i=0;i<inputs.length;i++){
	(function(i){
	 var j=i;
	 if(!as[j]){return;}
	 as[j].onclick = function(){
	 //var userid = eval('"' + decodeURIComponent(KISSY.Cookie.get('_nk_')) + '"');
	 //console.log(S.Cookie.get('login'))
	 //var coo = //console.log(typeof coo);
	 if(KISSY.Cookie.get('login')){
	 if(tag_arr[j] == "true"){
	 if(inputs[j].value == ""){
	 alert("请输入竞猜价格");
	 }else{
	 var h = document.body.offsetHeight;
	 dom.get("#zp_mask2").style.height = h + "px";
	 dom.get("#zp_mask2").style.display = "block";
	 var divs = S.query("#zp_yzm div");
	 dom.get("#zp_yzm").style.display = "block";
	 //预热页面
	 if(j == 4){
	 divs[1].innerHTML = "1+1=?";
	 var price = parseFloat($("ty_price").getAttribute("data-price")).toFixed(3),
		 user_value = parseFloat(inputs[j].value).toFixed(3);
	 dom.get("#yz_btn").onclick = function(){
		 var inputV = S.query("#zp_yzm input")[0].value;
		 if(inputV != ""){
			 if(inputV == "2"){
				 dom.get("#zp_mask2").style.display = "none";
				 dom.get("#zp_yzm").style.display = "none";
				 divs[0].innerHTML = "";
				 S.query("#zp_yzm input")[0].value = "";
				 if(price === user_value){
					 msg(0);
				 }else{
					 msg(1);
				 }
			 }else{
				 divs[0].innerHTML = "验证码错误";
			 }
		 }else{
			 alert("请输入验证码！");
		 }
		 return false;
	 }
	 }else{
		 //GET1
		 var _sUrl = 'http://fengkuang.etao.com' + '?id=' + (j+1) + '&p=' + inputs[j].value;
		 S.getScript(_sUrl,function(){
				 divs[0].innerHTML = "";
				 var ques = json.que;
				 if(ques != ""){
				 divs[1].innerHTML = ques;
				 S.query("#zp_yzm input")[0].value = eval(ques.substring(0,ques.length-1));//Kelvin add
				 console.log('Kques:'+ques);
				 }else{
				 divs[1].innerHTML = '<img src="http://img02.taobaocdn.com/tps/i2/T16WJqXaXeXXXXXXXX-32-32.gif" class="onload_img"/>';
				 }
				 dom.get("#yz_btn").onclick = function(){
				 var inputV = S.query("#zp_yzm input")[0].value;
				 if(inputV != ""){
				 if(json.hit == "1002"){
				 //GET2
				 var _tUrl = 'http://fengkuang.etao.com' + '?id=' + (j+1) + '&p=' + inputs[j].value +'&key=' + inputV + '&que=' + ques;
				 dom.get("#zp_mask2").style.display = "none";
				 dom.get("#zp_yzm").style.display = "none";
				 S.query("#zp_yzm input")[0].value = "";
				 S.getScript(_tUrl,function(){
					 if(json.win == "1001"){
					 	msg(3);
						alert('HACKED!')
					 }else{
					 //msg(2);
					 console.log('json.win='+json.win);
					 }
					 });
				 }else{
					 //divs[0].innerHTML = "价格没有猜对哦！";
					 console.log('Kwrong price...');
				 }
				 }else{
					 alert("请输入验证码！");
				 }
				 return false;
				 }
				 dom.get("#yz_btn").onclick();//Kelvin add
		 });
	 }
	 dom.get("#yz_close").onclick = function(){
		 dom.get("#zp_mask2").style.display = "none";
		 dom.get("#zp_yzm").style.display = "none";
		 divs[0].innerHTML = "";
		 S.query("#zp_yzm input")[0].value = "";
		 return false;
	 }
	 }
	 }
	 }else{
		 window.location.href = 'http://login.etao.com/?redirect_url=' + encodeURIComponent(window.location.href);
		 return false;
	 }
	 return false;
	 }
	})(i)
}
})(KISSY) 
/*javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','https://kelvin-mirex-svn.googlecode.com/svn/trunk/misc/xt.js');document.getElementById('zp_wrap').appendChild(e)})());*/
